package com.example.demo.web;

import com.example.demo.entity.Follow;
import com.example.demo.entity.Question;
import com.example.demo.param.dto.follow.DeleteFollowDto;
import com.example.demo.param.dto.follow.InsertFollowDto;
import com.example.demo.param.vo.FollowUserVO;
import com.example.demo.service.IFollowService;
import com.example.demo.service.ITokenService;
import com.example.demo.util.Json;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 关注控制器
 */
@Api(tags = "关注")
@RestController
@RequestMapping("follow")
public class FollowController extends BaseController {

    @Autowired private IFollowService followService;
    @Autowired private ITokenService tokenService;

    /**
     * 查询我的关注
     * @param token
     * @param page
     * @param pageSize
     * @return
     */
    @ApiOperation("获取我关注的人")
    @GetMapping("get/follow")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token" , value = "token" ,required = true, paramType = "query" , dataType = "String"),
            @ApiImplicitParam(name = "page" , value = "展示的页数" ,required = true, paramType = "query" , dataType = "int" , example = "1"),
            @ApiImplicitParam(name = "pageSize" , value = "每页展示几条" ,required = true, paramType = "query" , dataType = "int" , example = "10")
    })
    public Json<FollowUserVO> getMyFollow(@RequestParam String token,
                                          @RequestParam Integer page,
                                          @RequestParam Integer pageSize){
        String uid = this.verification(token);
        return new Json<FollowUserVO>(this.followService.getMyFollow(uid, page, pageSize));
    }

    /**
     * 查询我的粉丝
     * @param token
     * @param page
     * @param pageSize
     * @return
     */
    @ApiOperation("获取我的粉丝")
    @GetMapping("get/fans")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token" , value = "token" ,required = true, paramType = "query" , dataType = "String"),
            @ApiImplicitParam(name = "page" , value = "展示的页数" ,required = true, paramType = "query" , dataType = "int" , example = "1"),
            @ApiImplicitParam(name = "pageSize" , value = "每页展示几条" ,required = true, paramType = "query" , dataType = "int" , example = "10")
    })
    public Json<FollowUserVO> getMyFans(@RequestParam String token,
                                          @RequestParam Integer page,
                                          @RequestParam Integer pageSize){
        String uid = this.verification(token);
        return new Json<FollowUserVO>(this.followService.getMyFans(uid, page, pageSize));
    }

    /**
     * 关新增注
     * @param dto
     * @return
     */
    @ApiOperation("新增关注")
    @PostMapping("insert")
    public Json<Boolean> insert(@RequestBody InsertFollowDto dto) {
        String uid = this.tokenService.verification(dto.getToken());
        Boolean exit = this.followService.insert(uid,dto.getBeUserId());
        Json<Boolean> json = new Json<>(exit);
        return json;
    }

    /**
     * 取消关注
     * @param id
     * @param token
     * @return
     */
    @ApiOperation("取消关注")
    @DeleteMapping("delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id" , value = "id" , required = true , paramType = "query" , dataType = "String"),
            @ApiImplicitParam(name = "token" , value = "token" , required = true , paramType = "query" , dataType = "String")
    })
    public Json<Boolean> delete(@RequestParam String id, @RequestParam String token){
        this.verification(token);
        Boolean exit = this.followService.delete(id);
        Json<Boolean> json = new Json<>(exit);
        return json;
    }

    /**
     * 测试
     * @param id
     * @return
     */
    @ApiOperation("测试")
    @GetMapping("getById/{id}")
    public Json<Follow> getById(@ApiParam(name = "id", value = "ID", required = true) @PathVariable("id") String id){
        return new Json<Follow>(this.followService.getById(id));
    }


}
